/**
 * @Description:
 * @Author bianpengfei
 * @create 2022/9/19 12:31
 */
import Vue from 'vue'
import { debounce } from '@bianpengfei/utils'

export function useWindowSize() {
  const state = Vue.observable({ width: 0, height: 0 })
  const resize = () => {
    state.width = (document.documentElement.clientWidth || document.body.clientWidth) + 'px'
    state.height = (document.documentElement.clientHeight || document.body.clientHeight) + 'px'
  }
  const _debounceResize = debounce(resize, 300)
  window.addEventListener('resize', _debounceResize, false)
  resize()
  return state
}
